"""
API响应工具
"""
from flask import jsonify
from typing import Any, Dict


def success_response(message: str, data: Any = None, code: str = "200") -> Dict:
    """成功响应"""
    response = {
        "code": code,
        "message": message
    }
    if data is not None:
        response["data"] = data
    return jsonify(response)


def error_response(message: str, data: Any = None, code: str = "500") -> Dict:
    """错误响应"""
    response = {
        "code": code,
        "message": message
    }
    if data is not None:
        response["data"] = data
    return jsonify(response)